<?php
/**
 * Created by PhpStorm.
 * User: Yieong
 * Date: 14/11/19
 * Time: 下午8:12
 */

class ModCode extends Model {

    protected $table = 'code';

    // 表名
    public function tableName(){
        return $this->table;
    }

    public static function model($className=__CLASS__){
        return parent::model($className);
    }

    public function getDbConnection(){
        return Yii::app()->dbOss;
    }

    public function select($params){
        if(!empty($params['pool_id'])){
            $where .= ' WHERE pool_id = :pool_id ';
            $args[':pool_id'] = $params['pool_id'];
        }
        
        if(!empty($params['code_number'])){
        	$where .= " AND code_number like :code_number ";
        	$args['code_number'] = '%'.$params['code_number'].'%';
        }
        
        if(!empty($params['is_use'])){
            $where .= ' AND is_use = :is_use ';
            $args[':is_use'] = $params['is_use'];
        }
        
        $sql = "SELECT * FROM {$this->table} {$where} ORDER BY id DESC";        
        $result = $this->getDbConnection()->getAll($sql, $args);
        return $result;
    }
    
    /**
     * 批量添加
     * @param unknown $params
     * @return unknown
     */
    public function multiAdd($params){
    	$result = $this->getDbConnection()->multiInsert($params, $this->table, FALSE);
    	return $result;
    }
    

    
} 